package com.eric.enderslastgame.threads;

import android.view.SurfaceHolder;

import com.eric.enderslastgame.EndersGamePanel;

public class SetSwitchThread extends Thread {

	private static final String TAG = SetSwitchThread.class.getSimpleName();

	// Surface holder that can access the physical surface
	private SurfaceHolder surfaceHolder;
	// The actual view that handles inputs
	// and draws to the surface
	private EndersGamePanel gamePanel;

	public SetSwitchThread(SurfaceHolder surfaceHolder,
			EndersGamePanel gamePanel) {
		super();
		this.surfaceHolder = surfaceHolder;
		this.gamePanel = gamePanel;
	}

	@Override
	public void run() {
		while (EndersGamePanel.inGame) {
			gamePanel.humans.get(gamePanel.currentSetGen).incoming = false;
			
			int randomSetGen = (int) (Math.random() * (gamePanel.sets - 1));
			
			while (gamePanel.currentSetGen == randomSetGen) {
				randomSetGen = (int) (Math.random() * (gamePanel.sets - 1));
				System.out.println("Finding a random number");
			}
			gamePanel.currentSetGen = randomSetGen;
			gamePanel.humans.get(gamePanel.currentSetGen).incoming = true;

			if (gamePanel.setSwitchSleepTime > 0) {
				try {
					sleep(gamePanel.setSwitchSleepTime);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
